/**
 * @author yinyuejia
 * @file 同一挂载全局方法
 */
import * as ElementPlusIconsVue from '@element-plus/icons-vue';

import config from '@/config';
import i18n from '@/locale';
import permission, { permissionHandler } from '@/utils/permission';
import { message, messageBox } from '@/plugin/elementplus';

export default {
  install: (app: any) => {
    app.config.globalProperties.$config = config;
    // @ts-ignore
    app.config.globalProperties.$t = i18n.global.t;
    app.config.globalProperties.$hasPermission = permissionHandler;
    app.config.globalProperties.$permission = permissionHandler;
    app.config.globalProperties.$message = message;
    app.config.globalProperties.$messageBox = messageBox;
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component);
    }
    app.directive('permission', permission); // 自定义指令 用法 v-permission="['xx.xx']"
  },
};
